package com.example.demo.controller;

import com.example.demo.model.Report;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
import com.example.demo.service.ReportService;

import java.util.List;

@RestController
@RequestMapping("/api/report")
public class ReportController {
    @Autowired
    private ReportService reportService;

    @PostMapping
    public ResponseEntity<?> createReport(@RequestParam Long torrentId,
                                          @RequestParam String reason,
                                          @RequestParam String description,
                                          Authentication authentication) {
        Long userId = Long.parseLong(authentication.getName());
        reportService.createReport(torrentId, userId, reason, description);
        return ResponseEntity.ok().build();
    }

    @GetMapping("/pending")
    public ResponseEntity<List<Report>> getPendingReports() {
        return ResponseEntity.ok(reportService.getPendingReports());
    }
}